package com.east.sng.entity.param;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @author east
 * @date: 2020/12/27
 * @Description: course information receive param javabean
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CourseParam {

    @NotNull(message = "{param.id.notnull}")
    private Integer  courseId;
    @NotBlank(message = "{courseparam.coursename.notblank}")
    private String  courseName;
    @NotNull(message = "{courseparam.courseduration.notnull}")
    @Range(min = 6,max = 12,message = "{courseparam.courseduration.range}")
    private Double  courseDuration;
    @NotNull(message = "{courseparam.courseprice.notnull}")
    private Double coursePrice;
    @NotBlank(message = "{courseparam.minage.notblank}")
    @Range(min = 6,max = 16,message = "{courseparam.minage.range}")
    @Pattern(regexp = "^([1-9][0-9]*){1,2}$",message = "{courseparam.minage.notblank}")
    private String  minAge;
    @NotBlank(message = "{courseparam.maxage.notblank}")
    @Range(min = 6,max = 16,message = "{courseparam.maxage.range}")
    @Pattern(regexp = "^([1-9][0-9]*){1,2}$",message = "{courseparam.maxage.notblank}")
    private String  maxAge;
    @NotBlank(message = "{courseparam.coursetypename.notblank}")
    @Pattern(regexp = "^([1-9][0-9]*)+$",message = "{courseparam.coursetypename.notblank}")
    private String  courseTypeName;
    @NotBlank(message = "{courseparam.classroomname.notblank}")
    @Pattern(regexp = "^([1-9][0-9]*)+$",message = "{courseparam.classroomname.notblank}")
    private String  classroomName;
    @NotBlank(message = "{courseparam.teachername.notblank}")
    @Pattern(regexp = "^([1-9][0-9]*)+$",message = "{courseparam.teachername.notblank}")
    private String  teacherName;

    /**
     * 比较最小年龄和最大年龄
     * @return 最大年龄是否大于最小年龄
     */
    public boolean compareAge(){
        return Integer.parseInt(this.maxAge)-Integer.parseInt(this.minAge)<0;
    }

}
